from langchain_community.embeddings import ModelScopeEmbeddings
from langchain_community.vectorstores import Chroma

# 生成向量（embedding）
model_id = "./nlp_gte_sentence-embedding_chinese-base"
embeddings = ModelScopeEmbeddings(model_id=model_id)
db = Chroma.from_texts(
    ids=["1", "2", "3"],
    texts=[
        "Toothbrushes can be returned up to 360 days after purchase if unopened.",
        "Shipping is free of charge for all orders.",
        "Shipping normally takes 2-3 business days"
    ],
    embedding=embeddings
)

# 检索
query = "What is your return policy for tooth brushes?"
docs = db.similarity_search(query, k=2)

# 打印结果
for doc in docs:
    print("===")
    print("metadata:", doc.metadata)
    print("page_content:", doc.page_content)
